package com.beiben.system.hours.controller;

import java.util.List;
import java.util.stream.Collectors;

import com.beiben.system.hours.domain.Hours;
import com.beiben.system.hours.service.IHoursService;
import com.ruoyi.common.core.domain.entity.SysRole;
import com.ruoyi.common.core.domain.entity.SysUser;
import com.ruoyi.common.core.domain.model.LoginUser;
import com.ruoyi.common.utils.ServletUtils;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.framework.web.service.TokenService;
import com.ruoyi.system.service.ISysPostService;
import com.ruoyi.system.service.ISysRoleService;
import com.ruoyi.system.service.ISysUserService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 工时管理Controller
 * 
 * @author xgq
 * @date 2020-08-24
 */
@RestController
@RequestMapping("/system/hours")
public class HoursController extends BaseController
{
    @Autowired
    private IHoursService hoursService;


    /**
     * 查询工时管理列表
     */
    @PreAuthorize("@ss.hasPermi('system:hours:list')")
    @GetMapping("/list")
    public TableDataInfo list(Hours hours)
    {
        startPage();
        List<Hours> list = hoursService.selectHoursList(hours);
        return getDataTable(list);
    }

    /**
     * 导出工时管理列表
     */
    @PreAuthorize("@ss.hasPermi('system:hours:export')")
    @Log(title = "工时管理", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(Hours hours)
    {
        List<Hours> list = hoursService.selectHoursList(hours);
        ExcelUtil<Hours> util = new ExcelUtil<Hours>(Hours.class);
        return util.exportExcel(list, "hours");
    }

    /**
     * 获取工时管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:hours:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(hoursService.selectHoursById(id));
    }

    /**
     * 新增工时管理
     */
    @PreAuthorize("@ss.hasPermi('system:hours:add')")
    @Log(title = "工时管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Hours hours)
    {
        return toAjax(hoursService.insertHours(hours));
    }

    /**
     * 修改工时管理
     */
    @PreAuthorize("@ss.hasPermi('system:hours:edit')")
    @Log(title = "工时管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Hours hours)
    {
        return toAjax(hoursService.updateHours(hours));
    }

    /**
     * 删除工时管理
     */
    @PreAuthorize("@ss.hasPermi('system:hours:remove')")
    @Log(title = "工时管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(hoursService.deleteHoursByIds(ids));
    }

    /**
     * 状态修改
     */
    @PreAuthorize("@ss.hasPermi('system:hours:edit')")
    @Log(title = "工时管理", businessType = BusinessType.UPDATE)
    @PutMapping("/changeState")
    public AjaxResult changeState(@RequestBody Hours hours)
    {
        return toAjax(hoursService.updateHoursState(hours));
    }


}
